package com.jdym.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jdym.R;
import com.jdym.entity.CoBank;
import com.jdym.entity.PopularLoan;
import com.jdym.service.CoBankService;
import com.jdym.service.PopularLoanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@CrossOrigin
public class PopularLoanController {

    @Autowired
    PopularLoanService popularLoanService;
    @Autowired
    CoBankService coBankService;
    @ResponseBody
    @RequestMapping("/getAllPopularLoan")
    public R getAllPopularLoan(){

        List<PopularLoan> popularLoans=popularLoanService.getAllPopularLoan();
        return R.ok().data("popularLoans",popularLoans);
    }

    @RequestMapping("/Ploan")
    public String Ploan(@RequestParam("plId") int plId, Model model){
        System.out.println("热门："+plId);
       PopularLoan popularLoans=popularLoanService.getPopularLoanById(plId);
        //        获取到所有的合作银行
        List<CoBank> coBanks= coBankService.getBaseMapper().selectList(null);

        model.addAttribute("coBanks",coBanks);
        System.out.println("PL:"+popularLoans);
       model.addAttribute("PL",popularLoans);
        return "borrow_details";
    }
}
